package com.e.dianshang.service.impl;

import com.e.dianshang.mapper.OrderMapper;
import com.e.dianshang.pojo.Order;
import com.e.dianshang.service.OrderService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author Tian同學
 * @Date 2020/11/9 19:00
 * @Version 1.0
 */
@Service("orderService")
public class OrderServiceImpl implements OrderService {

    @Resource
    OrderMapper orderMapper;

    /**
     * 根据微信id查询购物车列表
     * @param openid
     * @return
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.SUPPORTS,rollbackFor = {Throwable.class})
    public List<Map> getList(String openid) {
        return orderMapper.getList(openid);
    }

    /**
     * 删除购物车商品
     * @param list
     * @return
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED,rollbackFor = {Throwable.class})
    public int deleteBatch(List<Integer> list) {
        return orderMapper.deleteBatch(list);
    }

    /**
     * 移入关注后删除购物车对应商品
     * @param id
     * @return
     */
    @Override
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED,rollbackFor = {Throwable.class})
    public int delete(Integer id) {
        return orderMapper.deleteByPrimaryKey(id);
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED,rollbackFor = {Throwable.class})
    public int updateQuantity(Order order) {

        return orderMapper.updateByPrimaryKeySelective(order);
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.SUPPORTS,rollbackFor = {Throwable.class})
    public Order select(Integer id) {
        return orderMapper.selectByPrimaryKey(id);
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED,rollbackFor = {Throwable.class})
    public int updateGuiGe(Order order) {
        return orderMapper.updateByPrimaryKeySelective(order);

    }

}
